package main

import (
	"fmt"
	"log"
	"net/http"
	"net/rpc"
	"text/template"
)

type UserInfo struct {
	Name   string
	Gender string
	Age    int
}

func indexHandler(w http.ResponseWriter, r *http.Request) {
	tmpl, err := template.ParseFiles("./index.html")
	if err != nil {
		fmt.Println("create template failed,err:", err)
		return
	}
	userInfo := UserInfo{
		Age: 23, Name: "杨子平", Gender: "男",
	}
	tmpl.Execute(w, userInfo)

	//number := rand.Intn(1)
	//if number == 0 {
	//	time.Sleep(time.Second * 1)
	//	fmt.Fprintf(w, "slow response")
	//	return
	//}
	//fmt.Fprint(w, "quick response")
}
func test11() {
	http.HandleFunc("/", indexHandler)
	err := http.ListenAndServe(":8000", nil)
	if err != nil {
		panic(err)
	}
}

type Args struct {
	A, B int
}

func main() {
	client, err := rpc.Dial("tcp", "127.0.0.1:1234")
	if err != nil {
		log.Fatal("dialing:", err)
	}

	args := Args{9, 5}
	var reply int
	err = client.Call("Arith.Multiply", &args, &reply)
	if err != nil {
		log.Fatal("arith error:", err)
	}
	fmt.Printf("Result: %d\n", reply)
}
